/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dawnland02.model.action;

import dawnland02.model.action.controller.ActionController;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 * @author Petru Obreja (obrejap@yahoo.com)
 */
public class Action {
    private ActionType actionType;
    private Map<ActionParam, Object> actionParams;
    private ActionController actionController;

    private ActionStep currentStep;

    Action(ActionType actionType){
        this.actionType = actionType;
        currentStep = ActionStep.ACTION_BEFORE_INIT;
        actionParams = new HashMap<ActionParam, Object>();
    }

    Action(ActionType actionType, Map<ActionParam, Object> actionParams){
        this(actionType);
        this.actionParams = actionParams;
    }

    public ActionType getActionType(){
        return actionType;
    }

    public ActionController getActionController(){
        return actionController;
    }

    public void setActionController(ActionController actionController) {
        this.actionController = actionController;
    }

    public Object getValueForActionParam(ActionParam actionParam){
        return actionParams.get(actionParam);
    }
    
    public void addValueForActionParam(ActionParam actionParam, Object value){
        actionParams.put(actionParam, value);
    }

    public ActionStep getCurrentStep() {
        return currentStep;
    }

    public void setCurrentStep(ActionStep currentStep) {
        this.currentStep = currentStep;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("A:").append(actionType).append(" ").append(currentStep);
        if(actionParams.size()>0){
            stringBuilder.append(" (");
            for(Entry<ActionParam, Object> actionParam : actionParams.entrySet()){
                stringBuilder.append(actionParam.getKey()).append("-").append(actionParam.getValue()).append(" ");
            }
            stringBuilder.append(")");
        }
        return stringBuilder.toString();
    }
}
